package testcases;
import java.net.MalformedURLException;
import java.rmi.AlreadyBoundException;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.sql.SQLException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import o.财务单据类型;
import org.junit.Test;
import blservice.document.DocumentBLService;
import server.boot.ServiceLoader;
import vo.AccountBookVo;
import vo.AccountItemVo;
import vo.DocumentVo;
import vo.AccountInAndOutDocumentVo;
import client.boot.BLServiceManager;
import db.Database;
import static org.junit.Assert.*;
public class Doc_accountInOut_test {
    DocumentBLService bl;   
	@Test
	public void test_add() throws SQLException, RemoteException, MalformedURLException, AlreadyBoundException, NotBoundException{
		Database.iniDatabase("localhost", 3306, "seac2", "seac2", "seac2");
		ServiceLoader.iniServiceLoader();
		BLServiceManager.setServerIP("localhost");
	 	AccountBookVo accountbookvo=new AccountBookVo();
	 	accountbookvo.setName("default");
	 	bl = BLServiceManager.load收付款单BLService(accountbookvo); 
	 	AccountInAndOutDocumentVo vo=new AccountInAndOutDocumentVo();
	 	vo.set单据类型(财务单据类型.收款单);
	 	vo.set客户("ivan");
	 	List<AccountItemVo> list=new ArrayList<AccountItemVo> ();
	 	AccountItemVo item=new AccountItemVo();
	 	item.set备注("");
	 	item.set转账金额(1000);
	 	item.set银行账户("123456");
	 	list.add(item);
	 	AccountItemVo item2=new AccountItemVo();
	 	item2.set备注("");
	 	item2.set转账金额(1000);
	 	item2.set银行账户("123456");
	 	list.add(item2);
	 	vo.set转账列表(list);
	    assertEquals(true,bl.add((DocumentVo)vo).isSuccessed());
	    AccountInAndOutDocumentVo vo2=new AccountInAndOutDocumentVo();
	 	vo2.set单据类型(财务单据类型.付款单);
	 	vo2.set客户("ivan");
	 	List<AccountItemVo> list2=new ArrayList<AccountItemVo> ();
	 	AccountItemVo item3=new AccountItemVo();
	 	item3.set备注("");
	 	item3.set转账金额(1000);
	 	item3.set银行账户("123456");
	 	list2.add(item3);
	 	AccountItemVo item4=new AccountItemVo();
	 	item4.set备注("");
	 	item4.set转账金额(1000);
	 	item4.set银行账户("123456");
	 	list2.add(item4);
	 	vo2.set转账列表(list2);
	    assertEquals(true,bl.add((DocumentVo)vo).isSuccessed());
	    //添加失败
	    AccountInAndOutDocumentVo vo3=new AccountInAndOutDocumentVo();
	 	vo3.set单据类型(财务单据类型.付款单);
	 	list2.add(item3);
	 	list2.add(item4);
	 	vo2.set转账列表(list2);
	    assertEquals("请完整单据！",bl.add((DocumentVo)vo).getFailMessage());
	    
	 }
	
@Test
	public void test_getUnapproval() throws MalformedURLException, RemoteException, NotBoundException, SQLException{
		BLServiceManager.setServerIP("localhost");
	 	AccountBookVo accountbookvo=new AccountBookVo();
	 	accountbookvo.setName("default");
	 	bl = BLServiceManager.load收付款单BLService(accountbookvo); 
	 	List<DocumentVo> list_exp=new ArrayList<DocumentVo>();
	 	DocumentVo v1=new DocumentVo();v1.set单据编号("SKD-20141223-00001");
	 	list_exp.add(v1);
	 	DocumentVo v2=new DocumentVo();v2.set单据编号("FKD-20141231-00002");
	 	list_exp.add(v2);
	 	List<DocumentVo> list=bl.getUnapproval();
	 	for(int i=0;i<list.size();i++){
	 		assertEquals(list_exp.get(i).get单据编号(),list.get(i).get单据编号());
	 	}
	}
	@Test
	public void test_getFrom_to() throws MalformedURLException, RemoteException, NotBoundException, SQLException, ParseException{
		BLServiceManager.setServerIP("localhost");
	 	AccountBookVo accountbookvo=new AccountBookVo();
	 	accountbookvo.setName("default");
	 	bl = BLServiceManager.load收付款单BLService(accountbookvo); 
	 	List<DocumentVo> list_exp=new ArrayList<DocumentVo>();
	 	DocumentVo v1=new DocumentVo();v1.set单据编号("SKD-20141223-00001");
	 	list_exp.add(v1);
	 	DocumentVo v2=new DocumentVo();v2.set单据编号("FKD-20141231-00002");
	 	list_exp.add(v2);
	 	DocumentVo from=new DocumentVo();DocumentVo to=new DocumentVo();
	 	from.setDate(new SimpleDateFormat("yyyy-MM-dd").parse("2014-11-20"));
	 	to.setDate(new SimpleDateFormat("yyyy-MM-dd").parse("2014-11-30"));
		List<DocumentVo> list=bl.get(from,to);
		assertEquals(0,list.size());
		
		DocumentVo from1=new DocumentVo();DocumentVo to1=new DocumentVo();
	 	from1.setDate(new SimpleDateFormat("yyyy-MM-dd").parse("2014-12-20"));
	 	to1.setDate(new SimpleDateFormat("yyyy-MM-dd").parse("2014-12-30"));
		List<DocumentVo> list2=bl.get(from1,to1);
		for(int i=0;i<list2.size();i++){
	 		assertEquals("JHD-20141223-00001",list2.get(i).get单据编号());
	 	}
		DocumentVo from2=new DocumentVo();DocumentVo to2=new DocumentVo();
	 	from2.setDate(new SimpleDateFormat("yyyy-MM-dd").parse("2014-12-20"));
	 	to2.setDate(new SimpleDateFormat("yyyy-MM-dd").parse("2014-12-30"));
		List<DocumentVo> list3=bl.get(from2,to2);
		for(int i=0;i<list3.size();i++){
	 		assertEquals(list_exp.get(i).get单据编号(),list3.get(i).get单据编号());
	 	}
		
	}
	@Test
	public void test_approve() throws MalformedURLException, RemoteException, NotBoundException, SQLException{
		BLServiceManager.setServerIP("localhost");
	 	AccountBookVo accountbookvo=new AccountBookVo();
	 	accountbookvo.setName("default");
	 	bl = BLServiceManager.load进退货单BLService(accountbookvo);
	 	//审批已审批报错
	 	DocumentVo v1=new DocumentVo();v1.set单据编号("SKD-20141223-00001");
	 	assertEquals("该单据已审批！",bl.approve(v1).getFailMessage());
	 	//审批成功查看
	 	DocumentVo v2=new DocumentVo();v2.set单据编号("FKD-20141223-00002");
	 	assertEquals("该单据已审批！",bl.approve(v2).getFailMessage());
	}
	 	
	
	
}
